import subprocess

def copy_to_clipboard_linux(text):
    process = subprocess.Popen(
        ['xclip', '-selection', 'clipboard'],
        stdin=subprocess.PIPE,
        close_fds=True
    )
    process.communicate(input=text.encode('utf-8'))

# 或者使用 xsel
def copy_to_clipboard_linux_xsel(text):
    process = subprocess.Popen(
        ['xsel', '--clipboard', '--input'],
        stdin=subprocess.PIPE,
        close_fds=True
    )
    process.communicate(input=text.encode('utf-8'))

text_to_copy = "Hello, world!"
copy_to_clipboard_linux(text_to_copy)  # 使用 xclip
# 或者: copy_to_clipboard_linux_xsel(text_to_copy)  # 使用 xsel
